<!-- 商品列表组件 -->
<template>
	<view>
		<view class="goodslist">
			<view class="goods-item" v-if="goods.goods_small_logo!=''">
				<radio :checked="goods.goods_state" color="#C00000"  v-if="showRadio" @click="radioClickHandler"></radio>
				<view class="goods-item-left" @click="getGoodsDetails(goods.goods_id)">
					 <image :src="goods.goods_small_logo" mode="widthFix"></image>
				</view>
				<view class="goods-item-right">
					<view class="goods-item-name">
						{{goods.goods_name}}
					</view>
					<view class="goods-item-price">
						<view>{{goods.goods_price}}</view>
						<uni-number-box @change="numChangeHandler" :min="1" :value="goods.goods_count" v-if="showNumberBox"></uni-number-box>
					</view>
				</view>
			</view>
		</view> 
	</view>
</template>
<script>
	import {mapGetters} from 'vuex'
	
	export default {
		computed: {
			...mapGetters('m_cart', ['total']),
		},
		props: {
			goods: {
				type: Object,
				default:{}
			},
			// 是否展示左侧的按钮
			showRadio:{
				type:Boolean,
				default:false
			},
			//是否展示showNumberBox
			showNumberBox:{
				type:Boolean,
				default:false
			}
			
		},
		methods: {
			setBadge() {
				uni.setTabBarBadge({
					index: 2,
					text: this.total + ''
				})
			},
			getGoodsDetails(goods_id){
				uni.navigateTo({
					url:'/subpkg/goods_detail/goods_detail?goods_id='+goods_id
				})
			},
			radioClickHandler(){
				this.$emit('radioChange',{
					goods_id:this.goods.goods_id,
					goods_state:!this.goods.goods_state
				})
				this.setBadge()
			},
			numChangeHandler(val){
				this.$emit('numChange',{
					goods_id:this.goods.goods_id,
					goods_count:Number(val)
				})
			}
		}
	}
</script>
<style lang="scss">
	.goodslist {
		padding: 2px 5px;
		font-size: 12px;
	}
	.goods-item {
		display: flex;
		border-bottom: 1px solid #f0f0f0;
		justify-content: space-between;
		align-items: center;
	}

	.goods-item-left {
		display: flex;
		justify-content:space-between;
		align-items: center;
		margin-right: 10px;
		image {
			width: 230rpx;
		}
	}
	.goods-item-right {
		display: flex;
		width: 400rpx;
		flex-direction: column;
		justify-content: space-between;
		.goods-item-price {
			color: red;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
	}
</style>
